package com.leo.base.event.listener;

import com.google.common.eventbus.Subscribe;
import com.leo.base.event.annotation.EventBusListener;
import com.leo.base.event.event.OrderChangeEvent;
import com.leo.base.event.event.OrderCreatedEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @ClassName OrderChangeListener
 * @Description
 * @Author wangss
 * @date 2020.09.20 20:20
 * @Version 1.0
 */
@Slf4j
@Component
@EventBusListener
public class OrderChangeListener {

    @Subscribe
    public void created(OrderCreatedEvent event) throws InterruptedException {
        long orderId = event.getOrderId();
        Thread.sleep(300);
        log.info("订单创建监听,发送短信，orderId=" + orderId);
    }

    @Async
    @Subscribe
    public void change(OrderChangeEvent event) throws InterruptedException {
        long orderId = event.getOrderId();
        Thread.sleep(200);
        log.info("订单修改监听，物流变化，orderId=" + orderId);
    }
}
